﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace WP7.LockerPlayer.ViewModels
{
    public class MediaPlayerViewModel : INotifyPropertyChanged
    {
        #region private properties
        private ArtistViewModel _currentArtist;
        private AlbumViewModel _currentAlbum;
        private TrackViewModel _nowPlaying;
        private int _CurrentIndex;
        private PlaylistViewModel _currentPlaylist;
        private System.Windows.Visibility _ShowPlay;
        private Visibility _ShowPause;
        
        #endregion

        public System.Windows.Visibility ShowPlay
        {get
            {
                return _ShowPlay; ;
            }
            set
            {
                _ShowPlay = value;
                NotifyPropertyChanged("ShowPlay");
                
            }
        }
        public System.Windows.Visibility ShowPause
        {
            get
            {
                
                return _ShowPause;
            }
            set
            {
                _ShowPause = value;
                NotifyPropertyChanged("ShowPause");

            }
        }
        public bool isPaused { get; set; }
        public bool isMuted { get; set; }

        public ObservableCollection<TrackViewModel> CurrentTracks { get; set; }
        public ObservableCollection<AlbumViewModel> CurrentAlbums { get; set; }
        public ArtistViewModel CurrentArtist
        {
            get
            {
                return _currentArtist;
            }
            set
            {
                 _currentArtist = value;
                  NotifyPropertyChanged("CurrentArtist");
                
            }
        }
        public AlbumViewModel CurrentAlbum
        {
            get
            {
                return _currentAlbum;
            }
            set
            {
                _currentAlbum = value;
                NotifyPropertyChanged("CurrentAlbum");

            }
        }
        public PlaylistViewModel CurrentPlaylist
        {
            get
            {
                return _currentPlaylist;
            }
            set
            {
                _currentPlaylist = value;
                NotifyPropertyChanged("CurrentPlaylist");

            }
        }
        public TrackViewModel NowPlaying
        {
            get
            {
                return _nowPlaying;
            }
            set
            {
                _nowPlaying = value;
                NotifyPropertyChanged("NowPlaying");

            }
        }
        public int CurrentIndex
        {
            get
            {
                return _CurrentIndex;
            }
            set
            {
                _CurrentIndex = value;
                NotifyPropertyChanged("CurrentIndex");

            }
        }
        public void SetNextTrack()
        {
            int temp = this.CurrentIndex + 1;
            if (temp >= this.CurrentTracks.Count)
            {
                temp = 0;
            }
            this.CurrentIndex = temp;
            if (this.CurrentTracks.Count > 0)
            {
                this.NowPlaying = this.CurrentTracks[temp];
            }
        }
        public void SetPreviousTrack()
        {
            int temp = this.CurrentIndex - 1;
            if (temp < 0)
            {
                temp = 0;
            }
            this.CurrentIndex = temp;
            if (this.CurrentTracks.Count > 0)
            {
                this.NowPlaying = this.CurrentTracks[temp];
            }
        }
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion

        public MediaPlayerViewModel()
        {
            this.CurrentAlbums = new ObservableCollection<AlbumViewModel>();
            this.CurrentTracks = new ObservableCollection<TrackViewModel>();
            this.CurrentIndex = 0;
        }
    }
}
